
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

const store=new Vuex.Store({
    state:{
        leftmenu:[
            { pathname: 'Home', name: '首页', path: '/' ,classname:'home',isleaf:true},
            { pathname: 'recommend', name: '为你打造', path: '/recommend' ,classname:'tj'},
            { pathname: '', name: '',isai:true,classname:'ai',isleaf:true},
            { pathname: 'following', name: '我的关注', path: '/following' ,classname:'at',cirmodulename:'CIR-FOLLOW',cirnum:0},
            { pathname: 'myCollection', name: '我的收藏', path: '/myCollection' ,classname:'fav',cirmodulename:'CIR-COLLECT',cirnum:0},
            { pathname: 'likes', name: '我的喜欢', path: '/likes' ,classname:'zan',cirmodulename:'CIR-FAV',cirnum:0},
            { pathname: 'browseRecords', name: '浏览记录', path: '/browseRecords',classname:'history' ,cirmodulename:'CIR-BROWSE',cirnum:0,hidecir:localStorage.getItem('IS-FTED-CIR-MSG')},
            { pathname: '', name: '',isSplit:true },
            { pathname: '', name: '特色专栏',isdesc:true },
            { pathname: 'games', name: '游戏', path: '/games' ,classname:'yx',cirmodulename:'CIR-GAME',cirnum:0,isleaf:true},
            { pathname: 'screenshots', name: '截图', path: '/screenshots?t=2' ,classname:'jt',cirmodulename:'CIR-IMAGE',cirnum:0,isleaf:true},
            // { pathname: 'shortVideo', name: '短视频', path: '/shortVideo' ,classname:'dsp'},
            { pathname: 'works', name: '作品', path: '/works' ,classname:'zp',cirmodulename:'CIR-WORK',cirnum:0},
            { pathname: 'articles', name: '文章', path: '/articles' ,classname:'wz',cirmodulename:'CIR-ARTICLE',cirnum:0},
            { pathname: 'rank', name: '排行榜', path: '/rank' ,classname:'phb',isnew:true},
            { pathname: 'recruit', name: '职位', path: '/recruit' ,classname:'zhp'},

            // { pathname: 'Home', name: '更多', 
            //   children:[
            //   { pathname: 'recruit', name: '职位', path: '/recruit',classname:'zhp' },
            //   { pathname: 'rank', name: '排行榜', path: '/rank' ,classname:'wz'},
            //   ]
            // }
        ],
        ishiddenbar:false,
        theme:localStorage.getItem('THM-STY')||'light'
    },
    mutations:{
        SET_LEFT_MENU:(state,value)=>{
            state.leftmenu=value;
        },
        SET_IS_HIDDEN_BAR:(state,value)=>{
            state.ishiddenbar=value;
        },
        SET_THEME:(state,value)=>{
            state.theme=value;
        }
    },
    actions:{
        setLeftMenu({commit},data){
            let menus=Object.assign([],this.state.leftmenu);
            if(localStorage.getItem('token'))
            {
                let uid=localStorage.getItem('userId');
                menus.map(item=>{
                if(item.cirmodulename){
                    let key='UT-'+uid+'-'+item.cirmodulename;
                    if(localStorage.getItem(key)){
                            item.cirnum=parseInt(localStorage.getItem(key));
                        }
                    }
                })
            }
            commit('SET_LEFT_MENU',menus);
        },
        setHiddenBar({commit},data){
            commit('SET_IS_HIDDEN_BAR',data);
        },
        setTheme({commit},data){
            commit('SET_THEME',data);
        }
    },
    getters:{
        leftmenu:state=>state.leftmenu,
        ishiddenbar:state=>state.ishiddenbar,
        theme:state=>state.theme
    }
})

export default store